package com.roy.HadoopRPCDemo;

import java.io.IOException;

import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.RPC.Builder;
import org.apache.hadoop.ipc.RPC.Server;
import org.apache.log4j.Logger;

import com.roy.HadoopRPCDemo.protocol.MyService;
import com.roy.HadoopRPCDemo.protocol.impl.MyServiceImpl;

public class RPCServer {

	private static Logger logger = Logger.getLogger(RPCServer.class);
	
	public static void main(String[] args) {
		logger.info("==============start build server on localhost:8888===========");
		Builder builder = new RPC.Builder(new Configuration());
		builder.setBindAddress("localhost")
		.setPort(8888)
		.setProtocol(MyService.class)
		.setInstance(new MyServiceImpl());
		logger.info(">>>>>>>>>>>>>>>>>>>starting server on localhost:8888>>>>>>>>>>>>>>>>>>>");
		try {
			Server server = builder.build();
			server.start();
		} catch (HadoopIllegalArgumentException e) {
			logger.info(">>>>>>>>>>>>>>>>>>>starting server failed :"+e.getMessage());
		} catch (IOException e) {
			logger.info(">>>>>>>>>>>>>>>>>>>starting server failed :"+e.getMessage());
		}
		logger.info("==============start server on localhost:8888 complented===========");
	}
}
